package com.aigou.admin.aigouspringboot.controller.admin;

import com.aigou.admin.aigouspringboot.common.LogScope;
import com.aigou.admin.aigouspringboot.entity.CarouselFigure;
import com.aigou.admin.aigouspringboot.result.Result;
import com.aigou.admin.aigouspringboot.service.CarouselFigureService;
import com.aigou.admin.aigouspringboot.utils.RandomUtil;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin/carouselFigure")
@Slf4j
public class CarouselFigureController {
    @Resource
    private CarouselFigureService carouselFigureService;

    @GetMapping
    @LogScope(title= "轮播图管理模块", content = "轮播图信息")
    public Result select(@RequestParam Integer current){
        PageInfo<CarouselFigure> pageInfo=carouselFigureService.selectCarouselFiguresByPage(current);
        return Result.success(pageInfo);
    }

    @GetMapping("/{id}")
    @LogScope(title= "轮播图管理模块", content = "根据id查找信息")
    public Result detail(@PathVariable String id){
        CarouselFigure carouselFigure=carouselFigureService.selectById(id);
        return Result.success(carouselFigure);
    }

    @DeleteMapping("/{id}")
    @LogScope(title= "轮播图管理模块", content = "根据id删除信息")
    public Result delete(@PathVariable String id){
        int i=carouselFigureService.deleteById(id);
        return i>0 ?Result.success():Result.error();
    }

    @PutMapping
    @LogScope(title= "轮播图管理模块", content = "修改信息")
    public Result edit(@RequestBody CarouselFigure carouselFigure){
        int i=carouselFigureService.edit(carouselFigure);
        return i>0 ?Result.success():Result.error();
    }

    @PostMapping("/save")
    @LogScope(title= "轮播图管理模块", content = "添加信息")
    public Result save(@RequestBody CarouselFigure carouselFigure){
        carouselFigure.setId(RandomUtil.getRandomNumber());
        int i=carouselFigureService.save(carouselFigure);
        return i>0 ?Result.success():Result.error();
    }
}
